﻿
function main() {
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var fenSiNum=viewJson.fenSiNum;
    var fanyeNum=viewJson.fanyeNum;
    var waitingTime=viewJson.waitingTime;

    var fenSiNumF=0;
	var resData = RequestEngine.getResData();
	var text = "";
	AccessibilityEngine.log("resData"+resData);
	var resJson = JSON.parse(resData);

	AccessibilityEngine.log("resJson"+resJson);
	if (resJson.resText != undefined && resJson.resText != "") {
		var resText = eval('(' + resJson.resText + ')');
		text = resText[0];
	}

	var type = resJson.type;	

    AccessibilityEngine.sleepEngine(10000);//等待
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
	
	var jixing = getXYByIdIndex(widget.pages.shouye.wode);
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    AccessibilityEngine.mockOnClickIdText(widget.pages.shouye.wode,"我");
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dy");//830
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
    AccessibilityEngine.sleepEngine(2000);//等待
    AccessibilityEngine.mockOnClickClassText("android.widget.TextView","好友列表");
	

	
	
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) {//更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
	if(AccessibilityEngine.checkUpText("暂无好友，左滑去发现吧") == ISTRUE){
		setTaskState("5", "您还没有好友哦~~~");
	}
	
	
    AccessibilityEngine.sleepEngine(1500);//等待

    for  (var i =0 ; i <fanyeNum; i ++ ){ //翻几页
        ScreenEngine.swipe(parseX(300), parseY(1260), parseX(300), parseY(215), 1500); //从下往上滑动
    }
	
	if (AccessibilityEngine.checkUpId("") == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
	
	
	
	
    while ( fenSiNumF < fenSiNum){ 
         var mingZiNum= AccessibilityEngine.getIdNum("com.ss.android.ugc.aweme:id/e2a");//获取列表个数	
        // howLog("mingZiNum"+mingZiNum);
        for  (var i =0 ; i <mingZiNum; i ++ ){ //循环点击名字列表
            AccessibilityEngine.mockOnClickIdIndex("com.ss.android.ugc.aweme:id/e2a",i); // 循环点击名字列表
            AccessibilityEngine.sleepEngine(waitingTime*1000);//等待
			    if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/e2a") == ISTRUE){
                    AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/e2a"); // 进入好友主页面
					//AccessibilityEngine.mockOnClickClassDesc("com.ss.android.ugc.aweme:id/bbr","发消息");
                    AccessibilityEngine.sleepEngine(2000);//等待                      
                     }
                    AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/d2q");//点击发消息框
					AccessibilityEngine.sleepEngine(1500);//等待					 
            if (type == 1){            				  

					if (AccessibilityEngine.checkUpId("com.ss.android.ugc.aweme:id/byx") == ISTRUE) { //判断是否存在:发送消息框
				    AccessibilityEngine.mockEditId("com.ss.android.ugc.aweme:id/byx", text); //赋值
				    AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/d2g"); //发送
				    AccessibilityEngine.sleepEngine(1000);
			         }
			        AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/bji");//点击返回
			        AccessibilityEngine.sleepEngine(500);
			        AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/js");//点击返回
			        AccessibilityEngine.sleepEngine(2000);					
                    fenSiNumF++;
                    if (fenSiNumF >= fenSiNum){
                        showLog("执行成功");
                        setTaskState("5", "脚本执行完毕");
						break;
                    }               

            } else if (type == 2 || type == 5){
                AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/b_3");//点击相机小图标
                AccessibilityEngine.sleepEngine(2000);
			    AccessibilityEngine.mockOnClickClassText("android.widget.TextView", "上传");
			    AccessibilityEngine.sleepEngine(2000);
			    AccessibilityEngine.mockOnClickClassText("android.widget.TextView", "图片");//点击图片
			    AccessibilityEngine.sleepEngine(8000);						
			    ScreenEngine.swipe(parseX(83), parseY(332), parseX(83), parseY(332), 500);//选中图片
			    AccessibilityEngine.sleepEngine(8000);
			if(text != null && text != ""){
				if( jixing == 1 ){// 判断机型
					ScreenEngine.swipe(parseX(145), parseY(945), parseX(145), parseY(945), 500);//点击"说点什么"
				} else if( jixing == 2 ){
					//ScreenEngine.swipe(parseX(176), parseY(1425), parseX(176), parseY(1425), 500); //点击"说点什么"
					AccessibilityEngine.mockOnClickClassText("android.widget.TextView", "说点什么…");
				}
				
				AccessibilityEngine.sleepEngine(2000);
				AccessibilityEngine.mockEditId("com.ss.android.ugc.aweme:id/aex", text); //赋值
				AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dcg");//点勾勾
				AccessibilityEngine.sleepEngine(10000);
			}			
			AccessibilityEngine.sleepEngine(5000);
		    AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/bic");//发送
			AccessibilityEngine.sleepEngine(8000);
			
				if( jixing == 1 ){// 判断机型
					ScreenEngine.swipe(parseX(51), parseY(100), parseX(51), parseY(100), 500);//点击返回
				} else if( jixing == 2 ){
					ScreenEngine.swipe(parseX(80), parseY(113), parseX(80), parseY(113), 500); //点击返回					
				}
              AccessibilityEngine.sleepEngine(500);
			  AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/js");//点击返回
                    fenSiNumF++;
                    if (fenSiNumF >= fenSiNum){
                        showLog("执行成功");
                        setTaskState("5", "脚本执行完毕");
                        throw SyntaxError();
                    }               

            }else if (type == 3 || type == 6){                  			
			AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/b_3");//点击相机小图标
			AccessibilityEngine.mockOnClickClassText("android.widget.TextView", "上传");
			AccessibilityEngine.sleepEngine(2000);
			ScreenEngine.swipe(parseX(88), parseY(322), parseX(88), parseY(322), 500);//点击第一个视频
			AccessibilityEngine.sleepEngine(10000);
			AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dtj");//下一步			
			AccessibilityEngine.sleepEngine(10000);
			
			if(text != null && text != ""){
			
			
				if( jixing == 1 ){// 判断机型
					ScreenEngine.swipe(parseX(145), parseY(945), parseX(145), parseY(945), 500);//点击"说点什么"
				} else if( jixing == 2 ){
					//ScreenEngine.swipe(parseX(243), parseY(1425), parseX(243), parseY(1425), 500); //点击"说点什么"
					AccessibilityEngine.mockOnClickClassText("android.widget.TextView", "说点什么…");
					//AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dbm"); 
					//AccessibilityEngine.mockOnClickIdIndex("com.ss.android.ugc.aweme:id/ako", 9);
					//ScreenEngine.swipe(parseX(350), parseY(128), parseX(350), parseY(128), 500); //点击"说点什么"
				}
						
				AccessibilityEngine.sleepEngine(2000);
				AccessibilityEngine.mockEditId("com.ss.android.ugc.aweme:id/aex", text); //赋值
				AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/dcg");//点勾勾
				AccessibilityEngine.sleepEngine(10000);
			}
			AccessibilityEngine.sleepEngine(10000);
			AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/bic");//发送
			AccessibilityEngine.sleepEngine(30000);
			
			if( jixing == 1 ){// 判断机型
					ScreenEngine.swipe(parseX(51), parseY(100), parseX(51), parseY(100), 500);//点击返回
				} else if( jixing == 2 ){
					ScreenEngine.swipe(parseX(80), parseY(113), parseX(80), parseY(113), 500); //点击返回					
				}
            AccessibilityEngine.sleepEngine(500);
			AccessibilityEngine.mockOnClickId("com.ss.android.ugc.aweme:id/js");//点击返回
			AccessibilityEngine.sleepEngine(2000);
                    sendMessageFunction(sendMessage);
                    fenSiNumF++;
                    if (fenSiNumF >= fenSiNum){
                        showLog("执行成功");
                        setTaskState("5", "脚本执行完毕");
                        throw SyntaxError();
                    }                

            }
								
        }
        if (AccessibilityEngine.checkUpClazzText(widget.classText.widgetByClass.textView, "没有更多了~") == ISFALSE) {
            ScreenEngine.swipe(parseX(300), parseY(1200), parseX(300), parseY(200), 1500); //从下往上滑动			
        }else {
            showLog("执行成功");
            setTaskState("5", "到底了");
            throw SyntaxError();
        }
    }
	setTaskState("5", "操作成功");
}

var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();